<template>
	<view>
		<view class="header-batch" id="header-batch">
			<view>
				请设置消息通知的场地
			</view>
			<view class="batch">
				<u-button type="primary" size="mini" @click="nav('./brand-message-set/brand-message-batch')">批量设置
				</u-button>
			</view>
		</view>
		<view class="search" id="search">
			<u-search placeholder="场地名称" v-model="page.storeName" :show-action="true" action-text="取消" :animation="true"
				height="35" @search="formatData" clearable></u-search>
		</view>
		<view class="main">
			<view class="card" v-if="list.length > 0">
				<scroll-view scroll-y @scrolltolower="reachBottom" :style="[{height: height + 'px'}]"
					lower-threshold="10">
					<view class="line" :class="index == list.length - 1 ? '' : 'line-bottom'" hover-class="u-cell-hover"
						hover-stay-time="150" v-for="(item,index) in list" :key="index"
						@click="nav('./brand-message-set/brand-message-set?storeIds='+JSON.stringify([item.id]))">
						<view class="left">
							<view style="margin-right: 20rpx;">{{item.storeName}}</view>
							<view>
								<u-tag :text="item.deviceCount + '台'" mode="dark" size="mini"/>
							</view>
						</view>
						<view class="right">
							<view v-if="item.noticeMessageContentId != null || item.noticeMessageTagId != null"
								class="soudn-settings">已设置</view>
							<view v-else>未设置</view>
							<view class="icon">
								<u-icon name="arrow-right" color="#999" size="15"></u-icon>
							</view>
						</view>
					</view>
					<u-loadmore :status="status" :load-text="loadText" style="padding: 30rpx 0 70rpx 0;" />
				</scroll-view>
			</view>
			<u-empty mode="list" v-else icon="http://cdn.uviewui.com/uview/empty/list.png"/>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				height: 0,
				brandInfo: {},
				list: [],
				status: 'loadmore',
				loadText: {
					loadmore: '轻轻上拉加载',
					loading: '稍等一会,正在努力为您加载...',
					nomore: '暂时没有更多了'
				},
				page: {
					pageNum: 1,
					storeName: '',
				},
			}
		},
		onLoad() {
			this.formatData();
		},
		onPullDownRefresh() {
			this.formatData();
		},
		onShow() {
			let _this = this;
			uni.$once('edit', function(res) {
				if (res == "true") {
					console.log("返回");
					_this.formatData();
				}
			})
		},
		mounted() {
			const query = uni.createSelectorQuery().in(this);
			query.select('#header-batch').boundingClientRect(data => {
				this.height = this.height - data.height;
			}).exec();
			query.select('#search').boundingClientRect(data => {
				this.height = this.height - data.height;
			}).exec();
			this.height = this.height - 30;
		},
		methods: {
			nav(url) {
				uni.navigateTo({
					url: url
				})
			},
			findData() {
				uni.showLoading({
					title: '请稍等...',
					mask: true
				})
				this.$api('merchantStore.findMerchantStoreList', this.page).then(res => {
					uni.hideLoading();
					uni.stopPullDownRefresh();
					if (res.data != null) {
						this.list.push(...res.data.list)
						this.page.pageNum = res.data.pageNum;
						if (this.page.pageNum >= res.data.pages) {
							this.status = 'nomore';
							return;
						}
					}
				})
			},
			formatData() {
				this.list = [];
				this.page.pageNum = 1;
				this.status = 'loadmore';
				this.findData();
				this.reachBottom();
			},
			reachBottom() {
				// console.log("-------------下拉加载---------- ----")
				if (this.status == 'nomore') {
					return;
				}
				this.status = 'loading';
				// 使用延迟实现加载动画效果
				setTimeout(() => {
					this.page.pageNum = ++this.page.pageNum;
					this.findData();
					this.status = 'loadmore';
				}, 500)
			}
		}
	}
</script>
<style lang="scss">
	page {
		background-color: $u-bg-color;
	}
	.header-batch{
		padding: $u-padding-large $u-padding-medium;
		display: flex;
		justify-content: space-between;
		align-items: center;
		background-color: white;
		color: #6072FF;
		font-size: $f-base;
		.batch{
			text-align: right;
		}
	}
	.search{
		background-color: white;
		padding: 0 $u-padding-medium $u-padding-medium $u-padding-medium;
	}
	.main {
		padding: 0 $u-padding-large;
		color: rgba(0, 0, 0, 0.75);
		font-size: $f-base;
		.card {
			margin: $u-margin-medium 0;
			padding: $u-padding-mini;
			background-color: white;
			border-radius:20rpx;
	
			.line {
				padding: $u-padding-large $u-padding-medium;
				display: flex;
				justify-content: space-between;
				align-items: center;
				border-radius:20rpx;
				
				.left{
					font-size: $uni-font-size-lg - 1;
					font-weight: 450;
					display: flex;
					justify-content: space-between;
					align-items: center;
				}
				
				.right {
					display: flex;
					justify-content: space-between;
					align-items: center;
					color: $u-tips-color;
					font-size: $uni-font-size-base;
					.soudn-settings{
						color: rgb(0,0,0);
					}
					.icon {
						margin-left: $u-margin-medium;
					}
				}
			}
			.line-bottom{
				border-bottom: 1rpx solid #fafafa;
			}
		}
	
	}
</style>
